__author__ = 'zhenjiao.su'
# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
class Active():
    def __init__(self,driver):
        self.driver=driver
    def find_element(self,element=None,type=None):
        if type==None:
            try:
                self.driver.find_element(*element)
                return self.driver.find_element(*element)
            except:
                print(u"定位失败,定位方法%s,定位属性%s"%(element[0],element[1]))
                raise SystemError
        else:
            element1="$".join(element)
            element2=(element1%type).split("$")
            try:
                self.driver.find_element(*element2)
                return self.driver.find_element(*element2)
            except:
                print(u"定位失败,定位方法%s,定位属性%s"%(element2[0],element2[1]))
                raise SystemError
    def find_elements(self,element=None,type=None):
        if type==None:
            try:
                self.driver.find_elements(*element)
                return self.driver.find_elements(*element)
            except:
                print(u"定位失败,定位方法%s,定位属性%s"%(element[0],element[1]))
                raise SystemError
        else:
            element1="$".join(element)
            element2=(element1%type).split("$")
            try:
                self.driver.find_elements(*element2)
                return self.driver.find_elements(*element2)
            except:
                print(u"定位失败,定位方法%s,定位属性%s"%(element2[0],element2[1]))
                raise SystemError
    def waite(self,element,time=120):
        time1=0
        while True:
            try:
                self.find_element(element)
                return True
            except:
                pass
            finally:
                time1=time1+1
                if time1==time:
                    return False













